package com.roy.rabbitmq.direct;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.GetResponse;
import com.roy.rabbitmq.RabbitMQUtil;

public class PullReceiver {
	private final static String QUEUE_NAME = "hello";
	/**
	 * 主动去服务器上获取消息的消费方式。一般还是会用while(true)保持一个频率长期消费。
	 * @param argv
	 * @throws Exception
	 */
	public static void main(String[] argv) throws Exception {
		Connection connection = RabbitMQUtil.getConnection();
		Channel channel = connection.createChannel();
		channel.queueDeclare(QUEUE_NAME, false, false, false, null);
	    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
	    GetResponse response = channel.basicGet(QUEUE_NAME, false);
	    System.out.println(new String(response.getBody(),"UTF-8"));
	    
	    GetResponse response2 = channel.basicGet(QUEUE_NAME, false);
	    System.out.println(new String(response2.getBody(),"UTF-8"));
	    
	    channel.close();
	    connection.close();
	}
}
